<!-- Loads initialization file with a couple of variables -->

<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Country of Citizenship Page
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/expand.css">
	</head>
	<body>
	<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<div class="message"></div>
		<%	
			try {
				
				Applicant a = new Applicant();
				
				/*** Get parameter via URL from previous page and write it 
					 to the applicant object ***/
			
				a.setFirstName(request.getParameter("firstName"));
				a.setName(request.getParameter("lastName"));
				a.setMiddleInitial(request.getParameter("middleInitial"));
				a.setMail(request.getRemoteUser());
				
				session.setAttribute("applicant", a);
			
		%>	
		
		<h2>Previous Data:</h2>
		
		<ol class="tree">
			<li><label for="general">General Information</label><input type="checkbox" id="general" />
				<ol> 
					<li>
						<table>
							<tr><td>First Name:</td><td><%= a.getFirstName() %></td></tr>
							<tr><td>Middle Initial:</td><td><%= a.getMiddleInitial() %></td></tr>
							<tr><td>Last Name:</td><td><%= a.getName() %></td></tr>
						</table>
					</li>
				</ol>
			</li>
		</ol>
			<hr>
			<br>
		
			Please select your country of citizenship from the list bellow.<br><br> 
				
		<%
 				/*** Get countries **/
 							
 				Location c = new Location();
 				ArrayList<Location> cAl = new ArrayList<Location>();	
 				cAl = c.getCountries();
 							
 				/*** Prepare auxiliary iterator 'col' to get a three-column format ***/
 								
 				int col = cAl.size()/3;
 								
 				out.print("<table><tr><td>");
 						
 				/*** Iteration for column one ***/
 							
 				for(int i=0; i<col; i++)
 				{
 					out.print("<a href=\"countryOfResidence.jsp" +
 				 			  "?countryOfCitizenship=" + cAl.get(i).getName() + "&id=" +
 							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
 				}
 							
 				out.print("</td><td>");
 					
 				/*** Iteration for column two ***/
 							
 				for(int i=col; i<(col+col); i++)
 				{
 					out.print("<a href=\"countryOfResidence.jsp" +
 							  "?countryOfCitizenship=" + cAl.get(i).getName() + "&id=" +
 							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
 				}
 							
 				out.print("</td><td>");
 								
 				/*** Iteration for column three ***/
 							
 				for(int i=(col+col); i<cAl.size(); i++)
 				{
 					out.print("<a href=\"countryOfResidence.jsp" +
 							  "?countryOfCitizenship=" + cAl.get(i).getName() + "&id=" +
 							  cAl.get(i).getId() + "\">" + cAl.get(i).getName() + "</a><br>");
 				}
 								
 				out.print("</td></tr></table>");
 							
 				}
 				catch(Exception e)
 				{
 					response.sendRedirect(BASE + "error.jsp");
 				}
 			%>
		</div>
	</body>
</html>